package com.cupk.service.impl;

import com.cupk.common.PageResult;
import com.cupk.dto.OrderDto;
import com.cupk.dto.ProviderDto;
import com.cupk.mapper.OrderMapper;
import com.cupk.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 名称OrderServiceImpl
 * 描述OrderService实现类
 *
 * @version 1.0
 * @author:XiongRuiKai
 * @datatime:2023-06-12 12:15
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;


    /**
     * "有x条正在实施的订单"分页查询
     * @param orderId 父订单编号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param page 页码
     * @param pageSize 每页返回的数据条目数
     * @return
     */
    @Override
    public PageResult<OrderDto> getQueryResultsWithPaging(
            String orderId,
            LocalDateTime startTime,
            LocalDateTime endTime,
            int page,
            int pageSize) {
        int start = (page - 1) * pageSize;
        List<OrderDto> orderList = orderMapper.getOrderPage(orderId, startTime, endTime, start, pageSize);
        long total = orderMapper.getOrderCount(orderId, startTime, endTime);
        return new PageResult<>(orderList, total);
    }

    /**
     * 计划采购分页查询
     * @param orderId 父订单编号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param page 页码
     * @param pageSize 每页返回的数据条目数
     * @return
     */
    @Override
    public PageResult<OrderDto> getQueryPlanResultsWithPaging(
            String orderId,
            LocalDateTime startTime,
            LocalDateTime endTime,
            int page,
            int pageSize) {
        int start = (page - 1) * pageSize;
        List<OrderDto> orderPlanList = orderMapper.getOrderPlanPage(orderId, startTime, endTime, start, pageSize);
        long total = orderMapper.getOrderPlanCount(orderId, startTime, endTime);
        return new PageResult<>(orderPlanList, total);
    }

    /**
     * 实施采购分页查询
     * @param orderId 父订单编号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param page 页码
     * @param pageSize 每页返回的数据条目数
     * @return
     */
    @Override
    public PageResult<OrderDto> getQueryExecuteResultsWithPaging(
            String orderId,
            LocalDateTime startTime,
            LocalDateTime endTime,
            int page,
            int pageSize) {
        int start = (page - 1) * pageSize;
        List<OrderDto> orderExecuteList = orderMapper.getOrderExecutePage(orderId, startTime, endTime, start, pageSize);
        long total = orderMapper.getOrderExecuteCount(orderId, startTime, endTime);
        return new PageResult<>(orderExecuteList, total);
    }
}
